<template>
  <view class="content">
    <view class="img-box">
      <image :src=" imgaePath " mode="widthFix" @click="zhanshitupian"></image>
    </view>
    <view class="enter-btn" v-if="type==0 && isNext">
      <button @click="submit('./contracter')">确认</button>
    </view>
    <view class="enter-btn" v-else-if="type==1" style="justify-content: space-around;">
      <button @click="submit('./contracter?id='+type)">确认</button>
    </view>
	<uni-popup ref="alertDialog" type="dialog">
		<uni-popup-dialog cancelText="关闭" confirmText="同意" title="用户你好" content="请选择合同样式" @confirm=""
		@close=""></uni-popup-dialog>
	</uni-popup>
    <view class="enter-btn" v-if="type==2">
      <button @click="">立即签约</button>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        imgurls: [],
        baseurl: '',
        type: 3,
        imgurl: '',
        headPath: '',
        isNext: false, // 默认不显示下一步 如果生成成功就才显示下一步的按钮
      }
    },
    computed: {
      imgaePath() {
        // console.log(this.headPath + this.imgurl);
        // return (this.headPath + this.imgurl).replace(/\\/g, '');
        console.log(this.imgurl);
        return (this.imgurl).replace(/\\/g, '');
      }
    },
    onLoad(options) {
      console.log(options);
      this.settitle(options.id);
	  
    },
    created() {
      this.headPath = this.path
	   
    },
    methods: {
      zhanshitupian() {
        this.imgurls.push(this.imgaePath)
        uni.previewImage({
          urls: this.imgurls
        })
      },
      submit(url) {
        uni.redirectTo({
          url: url
        })
      },
      settitle(type) { //根据不同值更改标题和按钮
        uni.showLoading({
          title: '模板生成中'
        })
        if (type == 0) {
          uni.setNavigationBarTitle({
            title: '合同模板',
          })
          this.type = type
          uni.$post(this.path + '/contract/toPicture/1-0', 
          {
            contractId: "1",
            contractNumber: "2",
            contractOtherRemark: "gh",
            contractOwnNumber: "1",
            contractPersonOneImgOne: "/person.png",
            contractPersonOneImgTwo: "/person.png",
            contractPersonOneTime: "2021-01-02 00:00:00",
            contractPersonTwoImgOne: "/person.png",
            contractPersonTwoTime: "2021-01-02 00:00:00",
            contractRelativeProjectId: 1,
            contractSalaryDayAdd: "1",
            contractSalaryDayBase: "100",
            contractSalaryMonthAdd: "100",
            contractSalaryMonthBase: "1000",
            contractSalaryNumberBase: "10",
            contractSalaryType: 0,
            contractStatus: 2,
            contractTryTime: 1,
            contractWorkAddress: "ggh",
            contractWorkContent: "fdgdf",
            contractWorkEnd: "2022-01-02 00:00:00",
            contractWorkStandard: "das",
            contractWorkStart: "2022-01-01 00:00:00",
            contractWorkTimeType: 0,
            contractWorkTryEnd: "2022-01-02 00:00:00",
            contractWorkTyStart: "2022-01-01 00:00:00",
            contractWorkType: "sdsda",
            id: 1,
            isEffective: 0,
            unitAddress: "sdas",
            unitContactAddress: "sasa",
            unitCreditCode: "1233",
            unitName: "asaas",
            unitOwnPerson: "saaa",
            unitOwnPhone: "17870605918",
            workerContactAddress: "asasa",
            workerIdentityCard: "360726200207085613",
            workerKindredAddress: "adasa",
            workerKindredName: "adsassa",
            workerKindredPhone: "17870601234",
            workerKindredRelative: "弟弟",
            workerName: "as",
            workerPhone: "17870605918",
            workerSex: 1
          }).then(res => {
            if (res.code == 200) {
              uni.hideLoading()
              uni.showToast({
                title: '生成成功',
                icon: 'none',
                duration: 500
              })
              this.isNext = true
              this.imgurl = res.data
              console.log('success-----3'); //type3请求成功
            } else {
              uni.hideLoading()
              uni.showToast({
                title: '生成失败',
                icon: 'none',
                duration: 1500
              })
              setTimeout(() => {
                uni.navigateBack()
              }, 1500)

            }
          })
        } else if (type == 1) {
          uni.setNavigationBarTitle({
            title: '生成合同',
          })
          this.type = type
		  uni.$post(this.path + '/contract/toPicture/2-0',
		  {
		    contractId: "1",
		    contractNumber: "2",
		    contractOtherRemark: "gh",
		    contractOwnNumber: "1",
		    contractPersonOneImgOne: "/person.png",
		    contractPersonOneImgTwo: "/person.png",
		    contractPersonOneTime: "2021-01-02 00:00:00",
		    contractPersonTwoImgOne: "/person.png",
		    contractPersonTwoTime: "2021-01-02 00:00:00",
		    contractRelativeProjectId: 1,
		    contractSalaryDayAdd: "1",
		    contractSalaryDayBase: "100",
		    contractSalaryMonthAdd: "100",
		    contractSalaryMonthBase: "1000",
		    contractSalaryNumberBase: "10",
		    contractSalaryType: 0,
		    contractStatus: 2,
		    contractTryTime: 1,
		    contractWorkAddress: "ggh",
		    contractWorkContent: "fdgdf",
		    contractWorkEnd: "2022-01-02 00:00:00",
		    contractWorkStandard: "das",
		    contractWorkStart: "2022-01-01 00:00:00",
		    contractWorkTimeType: 0,
		    contractWorkTryEnd: "2022-01-02 00:00:00",
		    contractWorkTyStart: "2022-01-01 00:00:00",
		    contractWorkType: "sdsda",
		    id: 1,
		    isEffective: 0,
		    unitAddress: "sdas",
		    unitContactAddress: "sasa",
		    unitCreditCode: "1233",
		    unitName: "asaas",
		    unitOwnPerson: "saaa",
		    unitOwnPhone: "17870605918",
		    workerContactAddress: "asasa",
		    workerIdentityCard: "360726200207085613",
		    workerKindredAddress: "adasa",
		    workerKindredName: "adsassa",
		    workerKindredPhone: "17870601234",
		    workerKindredRelative: "弟弟",
		    workerName: "as",
		    workerPhone: "17870605918",
		    workerSex: 1
		  }).then(res => {
		    if (res.code == 200) {
		      uni.hideLoading()
		      uni.showToast({
		        title: '生成成功',
		        icon: 'none',
		        duration: 500
		      })
		      this.isNext = true
		      this.imgurl = res.data
		      console.log('success-----3'); //type3请求成功
		    } else {
		      uni.hideLoading()
		      uni.showToast({
		        title: '生成失败',
		        icon: 'none',
		        duration: 1500
		      })
		      setTimeout(() => {
		        uni.navigateBack()
		      }, 1500)
		  
		    }
		  })

        } else {
          uni.setNavigationBarTitle({
            title: '合同签约',
          })
          this.type = type
        }

      }
    }
  }
</script>

<style lang="scss" scoped>
  .content {
    width: 750rpx;
    height: 100vh;

    .img-box {
      width: 95%;
      margin: 0 auto;

      image {
        width: 100%;
      }
    }

    .kongbai {
      width: 100%;
      height: 60rpx;
    }

    .enter-btn {
      position: fixed;
      bottom: 10px;
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;

      button {
        width: 80%;
        background-color: #2f67ff;
        height: 35px;
        line-height: 35px;
        color: white;
        font-size: 14px;
      }
    }
  }
</style>
